import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/store'
import * as types from '../store/types'

const Index = r => require.ensure([], () => r(require('../pages/index')), 'Home');
const Category = r => require.ensure([], () => r(require('../pages/category')), 'Category');
const SearchProduct = r => require.ensure([], () => r(require('../pages/search_product')), 'SearchProduct');
const HotSearch = r => require.ensure([], () => r(require('../pages/hot_search')), 'HotSearch');
const Material = r => require.ensure([], () => r(require('../pages/material')), 'Material');
const Register = r => require.ensure([], () => r(require('../pages/register')), 'Register');
const Agreement = r => require.ensure([], () => r(require('../pages/agreement')), 'Agreement');
const User = r => require.ensure([], () => r(require('../pages/user')), 'User');
const Login = r => require.ensure([], () => r(require('../pages/login')), 'Login');
const Auther = r => require.ensure([], () => r(require('../pages/auther')), 'Auther');
const BindPhone = r => require.ensure([], () => r(require('../pages/bind_phone')), 'BindPhone');
const Link = r => require.ensure([], () => r(require('../pages/link')), 'Link');
const UserSetting = r => require.ensure([], () => r(require('../pages/user_setting')), 'UserSetting');
const UserProfit = r => require.ensure([], () => r(require('../pages/user_profit')), 'UserProfit');
const UserOrder = r => require.ensure([], () => r(require('../pages/user_order')), 'UserOrder');
const UserTeam = r => require.ensure([], () => r(require('../pages/user_team')), 'UserTeam');
const UserTeamDetail = r => require.ensure([], () => r(require('../pages/user_team_detail')), 'UserTeamDetail');
const UserInvite = r => require.ensure([], () => r(require('../pages/user_invite')), 'UserInvite');
const UserLevel = r => require.ensure([], () => r(require('../pages/user_level')), 'UserLevel');
const UserHistory = r => require.ensure([], () => r(require('../pages/user_history')), 'UserHistory');
const UserService = r => require.ensure([], () => r(require('../pages/user_service')), 'UserService');
const ApplyAgent = r => require.ensure([], () => r(require('../pages/apply_agent')), 'ApplyAgent');
const ImproveLv = r => require.ensure([], () => r(require('../pages/improve_lv')), 'ImproveLv');
const PayLv = r => require.ensure([], () => r(require('../pages/user_pay_lv')), 'PayLv');
const CollectList = r => require.ensure([], () => r(require('../pages/collect_list')), 'CollectList');
const UserWithdraw = r => require.ensure([], () => r(require('../pages/user_withdraw')), 'UserWithdraw');
const Withdraw = r => require.ensure([], () => r(require('../pages/withdraw')), 'Withdraw');
const UserAccount = r => require.ensure([], () => r(require('../pages/user_account')), 'UserAccount');
const UserFresh = r => require.ensure([], () => r(require('../pages/user_fresh')), 'UserFresh');
const UserAssist = r => require.ensure([], () => r(require('../pages/user_assist')), 'UserAssist');
const Message = r => require.ensure([], () => r(require('../pages/message')), 'Message');
const ProductDetail = r => require.ensure([], () => r(require('../pages/product_detail')), 'ProductDetail');
const ShareGoods = r => require.ensure([], () => r(require('../pages/share_goods')), 'ShareGoods');
const UserInfo = r => require.ensure([], () => r(require('../pages/user_info')), 'UserInfo');
const SecondKill = r => require.ensure([], () => r(require('../pages/second_kill')), 'SecondKill');
const SecondKillDetail = r => require.ensure([], () => r(require('../pages/second_kill_detail')), 'SecondKillDetail');
const FashionTalk = r => require.ensure([], () => r(require('../pages/fashion_talk')), 'FashionTalk');
const FashionArticle = r => require.ensure([], () => r(require('../pages/fashion_article')), 'FashionArticle');
const ChangePassword = r => require.ensure([], () => r(require('../pages/change_password')), 'ChangePassword');
const Search = r => require.ensure([], () => r(require('../pages/search')), 'Search');
const SearchDetail = r => require.ensure([], () => r(require('../pages/search_detail')), 'SearchDetail');
const IndexGoodsSearch = r => require.ensure([], () => r(require('../pages/index_goods_search')), 'IndexGoodsSearch');
const IndexAppSearch = r => require.ensure([], () => r(require('../pages/index_app_search')), 'IndexAppSearch');
const TradeFloor = r => require.ensure([], () => r(require('../pages/trade_floor')), 'TradeFloor');

const routes = [
	{ path: '/', component: Index, name: '首页' },
	{ path: '/category', component: Category, meta: { keepAlive: true }, name: '分类' },
	{ path: '/search/product/:keyword/:id', component: SearchProduct, name: '搜索产品结果' },
	{ path: '/hotsearch', component: HotSearch, name: '超级搜' },
	{ path: '/material', component: Material, name: '素材' },
	{ path: '/register', component: Register, name: '注册' },
	{ path: '/agreement/:id', component: Agreement, name: '使用协议' },
	{ path: '/user', component: User, name: '我的' },
	{ path: '/login', component: Login, name: '登录' },
	{ path: '/auther', component: Auther, name: '微信登录' },
	{ path: '/bind/phone', component: BindPhone, name: '绑定手机号' },
	{ path: '/link', component: Link, name: '跳转' },
	{ path: '/user/setting', component: UserSetting, meta: { requireAuth: true }, name: '设置' },
	{ path: '/user/profit', component: UserProfit, meta: { requireAuth: true }, name: '收益' },
	{ path: '/user/order', component: UserOrder, meta: { requireAuth: true }, name: '订单' },
	{ path: '/user/team', component: UserTeam, meta: { requireAuth: true }, name: '团队' },
	{ path: '/user/team/detail/:id', component: UserTeamDetail, meta: { requireAuth: true }, name: '团队详情' },
	{ path: '/user/invite', component: UserInvite, meta: { requireAuth: true, keepAlive: true }, name: '邀请分享' },
	{ path: '/user/level', component: UserLevel, meta: { requireAuth: true }, name: '代理升级' },
	{ path: '/user/pay/lv', component: PayLv, meta: { requireAuth: true }, name: '支付升级' },
	{ path: '/user/history', component: UserHistory, meta: { requireAuth: true }, name: '我的足迹' },
	{ path: '/user/service', component: UserService, meta: { requireAuth: true }, name: '联系客服' },
	{ path: '/apply/agent', component: ApplyAgent, meta: { requireAuth: true }, name: '申请代理' },
	{ path: '/improve/lv', component: ImproveLv, meta: { requireAuth: true }, name: '升级合伙人' },
	{ path: '/collect/list', component: CollectList, meta: { requireAuth: true }, name: '收藏列表' },
	{ path: '/user/withdraw', component: UserWithdraw, meta: { requireAuth: true }, name: '挖券币' },
	{ path: '/user/withdraw/withdraw', component: Withdraw, meta: { requireAuth: true }, name: '提现' },
	{ path: '/user/account', component: UserAccount, meta: { requireAuth: true }, name: '收款账户' },
	{ path: '/user/fresh', component: UserFresh, name: '新手教程' },
	{ path: '/user/assist', component: UserAssist, name: '帮助中心' },
	{ path: '/message', component: Message, meta: { requireAuth: true }, name: '消息' },
	{ path: '/product/detail/:id', component: ProductDetail, meta: { requireAuth: true, keepAlive: true }, name: '商品详情' },
	{ path: '/share/goods/:id', component: ShareGoods, meta: { requireAuth: true }, name: '分享商品' },
	{ path: '/user/info', component: UserInfo, meta: { requireAuth: true }, name: '个人信息' },
	{ path: '/second/kill', component: SecondKill, meta: { keepAlive: true }, name: '秒杀专场' },
	{ path: '/second/kill/detail/:id', component: SecondKillDetail, meta: { keepAlive: true }, name: '秒杀商品详情' },
	{ path: '/fashion/talk', component: FashionTalk, name: '达人说' },
	{ path: '/fashion/article/:id', component: FashionArticle, meta: { requireAuth: true }, name: '达人文章' },
	{ path: '/trade/floor', component: TradeFloor, meta: { requireAuth: true }, name: '交易大厅' },
	{ path: '/user/change/password', component: ChangePassword, name: '修改密码' },
	{ path: '/search', component: Search, name: '搜索' },
	{ path: '/searchdetail/:id/:keyword', component: SearchDetail, meta: { keepAlive: true, scrollToTop: true }, name: '搜索结果' },
	{ path: '/indexgoodssearch/:id', component: IndexGoodsSearch, name: '首页商品链接' },
	{ path: '/IndexAppSearch/:id', component: IndexAppSearch, name: '全网购' },
]
// 页面刷新时，重新赋值token
if (window.localStorage.getItem('token')) {
    store.commit(types.LOGIN, window.localStorage.getItem('token'))
}

export default routes
